package com.xgry.bpm.config;

import com.xgry.bpm.config.interceptor.SysInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

@Configuration
public class Webconfig implements WebMvcConfigurer {

    @Resource
    private SysInterceptor sysInterceptor;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/uploadFile/**",
                "swagger-ui.html",
                "/static/**",
                "/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/",
                        "classpath:/static/",
                        "classpath:/META-INF/resources/webjars/");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        registry.addInterceptor(sysInterceptor)
                .excludePathPatterns(
                        "/swagger-resources/**",
                        "/webjars/**",
                        "/pages/**",
                        "/v2/**",
                        "/image/**",
                        "/css/**",
                        "/js/**",
                        "/miniUI/**",
                        "/swagger-ui.html/**");

    }

   /* @Override
    public void addCorsMappings(CorsRegistry registry) {
        //设置允许跨域的路径
        registry.addMapping("/**")
                //设置允许跨域请求的域名
                .allowedOrigins("*")
                //是否允许证书 不再默认开启
                .allowCredentials(true)
                //设置允许的方法
                .allowedMethods("*")
                //跨域允许时间
                .maxAge(3600);
    }*/

}
